package es.us.lsi.aws.api.server;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("rawtypes")
public class ControllerFactory {

	static Map<Class, Object> mapInstances;

	static {
		mapInstances = new HashMap<Class, Object>();
	}

	public static Controller getControllerInstance(Class clazz)
			throws InstantiationException, IllegalAccessException {

		Controller cInstance = null;
		if (clazz.getSuperclass().equals(Controller.class)) {

			if (mapInstances.containsKey(clazz)) {
				cInstance = (Controller) mapInstances.get(clazz);
			} else {
				Object obj = clazz.newInstance();
				cInstance = (Controller) obj;
			}
		}

		return cInstance;
	}

}
